<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>视频监控系统</title>
    <style>
        body {
            font-family: 'Electrolize', sans-serif;
            margin: 0;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background: url('beijing.png') center/cover no-repeat;
            position: relative;
            padding: 20px;
            color: #00ffcc;
            text-align: center;
        }

        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.6);
            z-index: -1;
        }

        .system-title {
            color: #00ffcc;
            text-shadow: 0 0 20px #00ffcc;
            font-size: 48px;
            margin-bottom: 30px;
            font-weight: bold;
            letter-spacing: 2px;
        }

        .video-container {
            background: linear-gradient(135deg, rgba(0, 255, 204, 0.1), rgba(0, 255, 204, 0.05));
            padding: 20px;
            border-radius: 20px;
            box-shadow: 0 0 30px rgba(0, 255, 204, 0.5);
            border: 1px solid rgba(0, 255, 204, 0.3);
            backdrop-filter: blur(15px);
            max-width: 90%;
            margin: 0 auto;
            position: relative;
        }

        .video-stream {
            max-width: 100%;
            max-height: 70vh;
            border: 2px solid #00ffcc;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 255, 204, 0.3);
        }

        .btn-container {
            display: flex;
            gap: 20px;
            margin-top: 30px;
        }

        .action-btn {
            padding: 15px 30px;
            border: none;
            border-radius: 10px;
            background: linear-gradient(135deg, #00ffcc, #00cc99);
            color: #0f0c29;
            font-size: 18px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 0 20px rgba(0, 255, 204, 0.5);
            font-weight: bold;
            min-width: 180px;
        }

        .action-btn:hover {
            background: linear-gradient(135deg, #00cc99, #009973);
            transform: scale(1.05);
            box-shadow: 0 0 30px rgba(0, 255, 204, 0.8);
        }

        .reconnect-btn {
            display: none;
            background: linear-gradient(135deg, #ff6600, #cc5200);
        }

        .reconnect-btn:hover {
            background: linear-gradient(135deg, #cc5200, #993d00);
        }

        .status-bar {
            margin-top: 20px;
            padding: 10px;
            background: rgba(0, 0, 0, 0.5);
            border-radius: 10px;
            border: 1px solid #00ffcc;
            box-shadow: 0 0 10px rgba(0, 255, 204, 0.2);
        }

        .error-overlay {
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.7);
            border-radius: 20px;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 10;
        }

        .error-message {
            color: #ff6600;
            font-size: 24px;
            margin-bottom: 20px;
            text-shadow: 0 0 10px #ff6600;
        }
    </style>
</head>
<body>
    <h1 class="system-title">工业废水监控视频</h1>
    
    <div class="video-container">
        <div class="error-overlay" id="errorOverlay">
            <div class="error-message" id="errorMessage">视频连接已中断</div>
            <button class="action-btn reconnect-btn" onclick="reconnectStream()">重新连接</button>
        </div>
        <img class="video-stream" src="./?action=stream" alt="实时监控视频流">
        <div class="status-bar">
            实时监控 | 状态: <span id="stream-status">连接中...</span>
        </div>
    </div>
    
    <div class="btn-container">
        <button class="action-btn" onclick="window.close()">返回主系统</button>
        <button class="action-btn reconnect-btn" id="reconnectBtn" onclick="reconnectStream()">重新连接</button>
    </div>

    <script>
        // 获取DOM元素
        const videoStream = document.querySelector('.video-stream');
        const statusElement = document.getElementById('stream-status');
        const errorOverlay = document.getElementById('errorOverlay');
        const errorMessage = document.getElementById('errorMessage');
        const reconnectBtn = document.getElementById('reconnectBtn');
        
        // 视频流状态检测
        function checkConnection() {
            if (videoStream.naturalWidth === 0) {
                statusElement.textContent = "连接中断";
                statusElement.style.color = "#ff6600";
                errorOverlay.style.display = "flex";
                reconnectBtn.style.display = "block";
                errorMessage.textContent = "视频连接已中断";
            } else {
                statusElement.textContent = "已连接";
                statusElement.style.color = "#00ff00";
                errorOverlay.style.display = "none";
                reconnectBtn.style.display = "none";
            }
        }
        
        // 重新连接函数
        function reconnectStream() {
            statusElement.textContent = "重新连接中...";
            statusElement.style.color = "#00ffcc";
            errorOverlay.style.display = "none";
            reconnectBtn.style.display = "none";
            
            // 添加时间戳防止缓存
            const timestamp = new Date().getTime();
            videoStream.src = `./?action=stream&t=${timestamp}`;
        }
        
        // 初始加载事件
        videoStream.onload = function() {
            checkConnection();
        };
        
        videoStream.onerror = function() {
            statusElement.textContent = "连接失败";
            statusElement.style.color = "#ff0000";
            errorOverlay.style.display = "flex";
            reconnectBtn.style.display = "block";
            errorMessage.textContent = "视频连接失败";
        };
        
        // 每5秒检查一次连接状态
        setInterval(checkConnection, 5000);
        
        // 初始检查
        window.addEventListener('load', function() {
            setTimeout(checkConnection, 2000);
        });
    </script>
</body>
</html>